package clsr.info.blog.common.pojo;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@NoArgsConstructor
public class JsonResponse<T> {

  public JsonResponse(T data, int code, boolean success) {
    this.data = data;
    this.code = code;
    this.success = success;
  }

  public JsonResponse(int code, boolean success, String message) {
    this.code = code;
    this.success = success;
    this.message = message;
  }

  private T data;
  private int code;
  private boolean success;
  private String message;

  public static <T> JsonResponse<T> success(T data) {
    return new JsonResponse<>(data, 200, true);
  }

  public static <T> JsonResponse<T> fail(String message) {
    return new JsonResponse<>(400, false, message);
  }

  public static <T> JsonResponse<T> fail(String message, int code) {
    return new JsonResponse<>(code, false, message);
  }
}
